package com.fho4565.core.cdgroup;

import net.minecraft.commands.CommandSourceStack;

import java.io.Serial;
import java.util.HashSet;

public class CommandGroup extends HashSet<SingleCommand> implements Cloneable {
    @Serial
    private static final long serialVersionUID = -4206175928231801104L;
    private String name;
    public CommandGroup(String name) {
        super();
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SingleCommand getByName(String name){
        return this.stream().filter(singleCommand -> singleCommand.getName().equals(name)).findFirst().orElse(null);
    }
    public boolean contains(String name){
        return this.stream().anyMatch(singleCommand -> singleCommand.getName().equals(name));
    }
    public void execute(CommandSourceStack stack){
        this.forEach(singleCommand -> {
            singleCommand.execute(stack);
        });
    }
    @Override
    public Object clone() {
        CommandGroup result;
        result = (CommandGroup)super.clone();
        result.clear();
        result.addAll(this);
        return result;
    }
}
